import re

# 匹配任意一个字符
ret = re.match(".","M")
print(ret.group())
ret = re.match("t.o","too")
print(ret.group())
ret = re.match("t.o","two")
print(ret.group())

print('-'*50)

#匹配[]中列举的字符
ret = re.match("h","hello Python")
print(ret.group())
ret = re.match("H","Hello Python")
print(ret.group())
ret = re.match("[hH]","hello Python")
print(ret.group())
ret = re.match("[hH]","Hello Python")
print(ret.group())
ret = re.match("[hH]ello Python","Hello Python")
print(ret.group())

print('-'*50)

# 匹配0到9
ret = re.match("[0123456789]Hello Python","7Hello Python")
print(ret.group())
ret = re.match("[0-9]Hello Python","7Hello Python")
print(ret.group())
ret = re.match("[0-35-9]Hello Python","7Hello Python")
print(ret.group())
# 下面这个正则不能够匹配到数字 4，因此 ret 为 None
ret = re.match("[0-35-9]Hello Python","4Hello Python")
#print(ret.group())

print('-'*50)

# 使用\d进行匹配数字
ret = re.match(r"嫦娥\d号","嫦娥1号发射成功")
print(ret.group())

ret = re.match(r"嫦娥\d号","嫦娥2号发射成功")
print(ret.group())

ret = re.match(r"嫦娥\d号","嫦娥3号发射成功")
print(ret.group())
